//index.js
//获取应用实例
 

const app=getApp()
Page({
  data: {
    navbarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '建档信息', //导航栏 中间的标题
    },
    navHeight: app.globalData.statusBarHeight * 2 + 86,
    contentData:null,
    nowDate:new Date(),
    pregnancyDay:null
  },


  onLoad:function(){
    var that = this;
    var nowDate = new Date();
    wx.request({
      url: app.getUrl('/xcx/pt/queryArchiveInfo'),
      method: 'GET',
      header: wx.getStorageSync('cookie'),
      success(res) {
        res.data.data.dataContent.forEach(item => {
          item.value = item.value == null ? '暂未填写' : item.value
        })
        that.setData({
          contentData: res.data.data.dataContent,
          nowDate: nowDate.getFullYear() + "-" + (nowDate.getMonth() + 1) + "-" + nowDate.getDate()
        })
        console.log(res)
        for(var i=0;i<that.data.contentData.length;i++){
          if (that.data.contentData[i].id =="Pub1100006"){
            var pregnancy = that.data.contentData[i].value
            var week = parseInt(pregnancy/7)
            var day = pregnancy - week*7
            if(day){
              that.setData({
                pregnancyDay: week + "周" + day + "天"
              })
            }else{
              that.setData({
                pregnancyDay: week + "周"
              })
            }
          }
        }
      }
    })
  },
  
  bindDateChange: function (e) {
    // 当前target 以及详情value
    var _this = this;
    _this.data.contentData.forEach(function(a,i){
        if(a.id == e.currentTarget.dataset.key){
          a.value = e.detail.value;
        }
    })
    var content = _this.data.contentData;
    _this.setData({
      contentData: content
    })
     
  },
 
  commitUserInfo:function(){
    var contentData = this.data.contentData;
   
    wx.request({
      url: app.getUrl('/xcx/pt/updateArchiveInfo'),
      method: 'POST',
      data: contentData,
      header: wx.getStorageSync('cookie'),
      success(res) {
        wx.showLoading({
          title: "个人资料更新成功"
        })
      }
    })
  }

})